package tutorial.java.swing;

import java.awt.Button;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ButtonDemo extends JFrame implements ActionListener{
	private JLabel label;
	private JButton button1;
	
	public ButtonDemo(){
		setSize(400, 300);
		setVisible(true);
		setLocation(500, 250);
		setResizable(false);
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		label = new JLabel("Hai Oanh");
		label.setSize(100, 50);
		add(label);
		
		JButton button = new JButton("Click Here");
		add(button, "North", 1);
		button.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				changeText();
			}
		});
		
		button1 = new JButton("Reset");
		add(button1, "South", 2);
		button1.addActionListener(this);
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		JButton b = (JButton) e.getSource();
		if(b == button1){
			label.setText("Hai Oanh");
		}
	}
	public void changeText(){
		label.setText("Nguyễn Văn Hai");
	}
	
	public static void main(String[] args){
		ButtonDemo buttonDemo = new ButtonDemo();
	}

	
}
